package tws

import (
	"go-web-scaffold/api"
	"net/http"

	"github.com/gin-gonic/gin"
)

type Context struct {
	Context *gin.Context
}

func NewContext(ctx *gin.Context) *Context {
	context := &Context{
		Context: ctx,
	}
	return context
}

// 常用的的功能通过 handle.go 挂载到 TWS Context 上
func (_this *Context) FileUploader(engine *gin.Engine) { // 文件上传
	api.FileUploader("/fileupload", "./files", func(result *api.UploadResult, ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"Message": result.Message,
			"Name":    result.Name,
			"Size":    result.Size,
		})
	}, engine)
}

func (_this *Context) Success(data map[string]interface{}) {
	_this.Context.JSON(http.StatusOK, gin.H{
		"statusCode": "200",
		"message":    "success",
		"data":       data,
	})
}
